package vip.specimen.system.config;

import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.*;

/**
 * *@Author: 余浪人
 * *@Date：2021/4/1 17:21
 * *@Email:yulangren520@Gmail.com
 * *@QQ:1368419640
 **/
@Configuration
@EnableSwagger2
@EnableSwaggerBootstrapUI
public class SwaggerConfig {
    @Bean
    public Docket createRestApi() {
        ParameterBuilder ticketPar = new ParameterBuilder();
        ticketPar.name("Authorization").description("用户授权token").modelRef(new ModelRef("String")).parameterType("header").required(true).build();
        List<Parameter> pars = new ArrayList<Parameter>() {{
            add(ticketPar.build());
        }};
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("vip.specimen.system.controller"))
                .paths(PathSelectors.any())
                .build().globalOperationParameters(pars).groupName("后台接口API");
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("specimen综合管理系统API接口文档")
                .description("specimen后台综合管理系统")
                .contact(new Contact("余浪人", "http://www.specimen.vip", "1368419640@qq.com"))
                .version("1.0")
                .build();
    }
}